package cn.edu.lzu.service.impl;

import cn.edu.lzu.common.assist.DataPage;
import cn.edu.lzu.common.assist.ResponseResult;
import cn.edu.lzu.dao.ClinicExamineItemMapper;
import cn.edu.lzu.entity.ClinicExamineItem;
import cn.edu.lzu.service.ClinicExamineItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @PackageName: cn.edu.lzu.service.impl
 * @ClassName: ClinicExamineItemServiceImpl
 * @Description: TODO
 * @Author: 张琦[QQ:3098086691]
 * @Date: 2020/3/29 18:31
 * @Version: 1.0
 */
@Service
public class ClinicExamineItemServiceImpl implements ClinicExamineItemService {
    @Resource
    private ClinicExamineItemMapper clinicExamineItemMapper;

    @Override
    public DataPage getCliExamineItems(long unitId, int currentPageNum, int pageSize) {
        int startIndex=(currentPageNum-1)*pageSize;
        List<ClinicExamineItem> clinicExamineItemList=clinicExamineItemMapper.selCliItemByUnitId(unitId, startIndex, pageSize);
        int totalCount=clinicExamineItemMapper.selCliItemTotalCount(unitId);
        DataPage dataPage=new DataPage();
        dataPage.setData(clinicExamineItemList);
        dataPage.setTotalCount(totalCount);
        dataPage.setCode(0);
        dataPage.setMsg("成功");
        return dataPage;
    }

    @Override
    public ResponseResult deleteCliItemById(Integer examineItemId) {
        int result=clinicExamineItemMapper.updDeleteCliItemById(examineItemId);
        ResponseResult responseResult = new ResponseResult();
        if (result == 1) {
            responseResult.setCode(1);
            responseResult.setMsg("删除成功！");
        } else {
            responseResult.setCode(0);
            responseResult.setMsg("删除失败");
        }
        return responseResult;
    }

    @Override
    public ResponseResult addCliItem(ClinicExamineItem clinicExamineItem) {
        int result=clinicExamineItemMapper.insAddCliItem(clinicExamineItem);
        ResponseResult responseResult=new ResponseResult();
        if(result==1){
            responseResult.setCode(1);
            responseResult.setMsg("添加成功！");
        }else{
            responseResult.setCode(0);
            responseResult.setMsg("添加失败！");
        }
        return responseResult;
    }

    @Override
    public List<ClinicExamineItem> getAllCliItems(long unitId) {
        List<ClinicExamineItem> clinicExamineItemList=clinicExamineItemMapper.selAllCliItems(unitId);
        return clinicExamineItemList;
    }
}
